package com.hy.domain;

import javax.persistence.TypedQuery;
import javax.validation.constraints.Size;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Gift {

    @Size(min = 2)
    private String name;

    @Size(max = 30000)
    private String content;

    private String image;
    
    private String keywords;
    
	private String description;

    public com.hy.domain.Gift getUp() {
        Gift gift = null;
        try {
            TypedQuery<Gift> query = entityManager.createQuery("from Gift g where g.id < :id order by g.id desc", Gift.class);
            query.setParameter("id", this.getId());
            query.setFirstResult(0).setMaxResults(1);
            gift = query.getSingleResult();
        } catch (Exception e) {
        }
        return gift;
    }

    public com.hy.domain.Gift getNext() {
        Gift gift = null;
        try {
            TypedQuery<Gift> query = entityManager.createQuery("from Gift g where g.id > :id", Gift.class);
            query.setParameter("id", this.getId());
            query.setFirstResult(0).setMaxResults(1);
            gift = query.getSingleResult();
        } catch (Exception e) {
        }
        return gift;
    }
}
